import { getDetailCode, getDetailName } from '@/api/support/swparamstation'
export const rule ={
  checkIp(rule, value, callback) {
    if(value!=null && value!=''){
      let values = value.replace(/\s+/g, "");
      var pattern = /^(1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|[1-9])\.(1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|\d)\.(1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|\d)\.(1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|\d)$/;
      if (pattern.test(values)) {
        callback()
      } else {
        callback(new Error('IP地址格式不规范！'))
      }
    }else{
      callback()
    }
  }
}
var validatorCode= function(rule,value,callback){
  if(value!=''){
    callback()
    // getDetailCode(value).then(response => {
    //   if(window.boxType ==='edit') callback()
    //   const result = response.data.data;
    //   if(result !== null){
    //     callback(new Error('车站编码已存在！'))
    //   }else{
    //     callback()
    //   }
    // } )
  }
}
var validatorName = function(rule,value,callback){
  if(value!=''){
    callback()
    // getDetailName(value).then(response => {
    //   if(window.boxType === 'edit') callback()
    //   const result = response.data.data;
    //   if(result !== null){
    //     callback(new Error('车站名称已存在！'))
    //   }else{
    //     callback()
    //   }
    // })
  }
}
export const tableOption = {
  "border": true,
  "index": true,
  "indexLabel": "序号",
  "stripe": true,
  "menuAlign": "center",
  "align": "center",
  "viewBtn": true,
  "editBtn": true,
  "delBtn": true,
  "labelWidth": 150,
  "column": [
	  {
	    "hide": true,
      "type": "input",
      "label": "唯一标识",
      "prop": "id",
      "display": false
    },	  {
      "type": "select",
      "label": "线路名称",
      "prop": "lineCode",
      "search": true,
      "searchSpan": 8,
      "searchLabelWidth": 150,
      "dicUrl": "/support/swparamline/dictAll",
      "props": {
        label: "name",
        value: "code"
      },
      rules: [{
        required: true,
        message: '请选择线路',
        trigger: 'change'
      },
    ]
    },	  {
      "type": "input",
      "label": "车站名称",
      "prop": "name",
      "search": true,
      "searchSpan": 8,
      "searchLabelWidth": 150,
      "rules": [{ required: true, message: "请输入车站名称"},
      {validator:validatorName, trigger:'blur'}
    ]
    },	  {
      "type": "input",
      "label": "车站编码",
      "prop": "code",
      "search": true,
      "searchSpan": 8,
      "searchLabelWidth": 150,
      "rules": [{ required: true, message: "请输入车站编码"},
      {
        validator: validatorCode, trigger: 'blur'
      }
    ]
    },	  {
      "type": "input",
      "label": "车站英文名称",
      "prop": "englishName",
      "search": true,
      "searchSpan": 8,
      "searchLabelWidth": 150,
      "rules": [{ required: true, message: "请输入车站英文名称"}]
    },{
      "type": "input",
      "label": "所属线路编码",
      "prop": "vlineCode",
      "rules": [{ required: true, message: "请输入所属线路编码"}]
    },	  {
      "type": "input",
      "label": "车站计算机的IP地址",
       width: "150px",
      "prop": "ipAddress",
      "search": true,
      "searchSpan": 8,
      "searchLabelWidth": 150,
      "labelWidth":150,
      rules: [
        { validator: rule.checkIp, trigger: 'blur' }
      ]
    }, {
      "type": "input",
      "label": "LCC的IP地址",
       width: "120px",
      "prop": "lcIpAddress",
      "search": true,
      "searchSpan": 8,
      "searchLabelWidth": 150,
      "labelWidth":120,
      rules: [
        { validator: rule.checkIp, trigger: 'blur' }
      ]
    },	  {
      "hide": true,
      "type": "input",
      "label": "顺序号",
      "prop": "sort"
    },	  {
      "type": "select",
      "label": "状态",
      "prop": "active",
      "dicData": [{
        "label": "启用",
        "value": true
      }, {
        "label": "未启用",
        "value": false
      }],
      "value": true,
      "clearable": false
    },	  {
      "hide": true,
      "type": "input",
      "label": "创建人ID",
      "prop": "creatorId",
      "display": false
    },	  {
      "hide": true,
      "type": "input",
      "label": "创建人名称",
      "prop": "creatorName",
      "display": false
    },	  {
      "hide": true,
      "type": "input",
      "label": "创建时间",
      "prop": "createTime",
      "display": false
    }  ]
}
